<%@ Control Language="C#" AutoEventWireup="true" CodeFile="QuoteList.ascx.cs" Inherits="Beta_fundies_controls_Quotes_QuoteList" %>
<asp:MultiView runat="server" ID="mviewQuotes">
    <asp:View runat="server" ID="viewQuotes">
        <asp:Repeater runat="server" ID="gridQuotes" EnableViewState="False">
            <HeaderTemplate>
                <script language="javascript" type="text/javascript">
                    function castvote(quoteID, vote)
                    { 
                        xmlHttp=GetXmlHttpObject();
                        if (xmlHttp==null)
                          {
                          // browser doesn't support AJAX
                          return;
                          }
                        var url="vote.aspx?q=" + quoteID +
                            "&vote=" + vote + 
                            "&sid="+Math.random();
                        xmlHttp.onreadystatechange = 
                            function() 
                            { 
                                if (xmlHttp.readyState==4)
                                {
                                    var myHTML = xmlHttp.responseText;
                                    var elementName = "vote_" + quoteID;
                                    var element = document.getElementById(elementName);
                                    if (element != null)
                                    {
                                        element.innerHTML = myHTML;
                                    }
                                    else
                                    {
                                        alert("null element: " + elementName);
                                    }
                                }
                            };
                        xmlHttp.open("GET",url,true);
                        xmlHttp.send(null);
                    }

                    function GetXmlHttpObject()
                    {
                        var xmlHttp=null;
                        try
                        {
                            // Firefox, Opera 8.0+, Safari
                            xmlHttp=new XMLHttpRequest();
                        }
                        catch (e)
                        {
                            // Internet Explorer
                            try
                            {
                                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
                            }
                            catch (e)
                            {
                                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                            }
                        }
                        return xmlHttp;
                    }
                </script>
            </HeaderTemplate>
            <ItemTemplate>
                <table class="quote">
                    <tr>
                        <td>
                            <p>
                                <div class="votepanel" id="vote_<%# Eval("ID") %>">
                                    <div class="voteheader">
                                        Average Rating: <%# Double.IsNaN((double)Eval("Rating")) ? "n/a" : Eval("Rating") %>
                                        <div class="small">Rated <%# Eval("NumberOfVoters") %> times.</div>
                                    </div>
                                    
                                    <table class="voteboxes">
                                        <tr><td colspan="5" class="small">Rate this quote:</td></tr>
                                        <tr><td class="v1"><asp:HyperLink runat="server" ID="lnkV1"
                                            Text="1"
                                            NavigateUrl='<%# GetNavigateUrl((long)Eval("ID"), 1) %>' /></td>
                                        <td class="v2"><asp:HyperLink runat="server" ID="lnkV2"
                                            Text="2"
                                            NavigateUrl='<%# GetNavigateUrl((long)Eval("ID"), 2) %>' /></td>
                                        <td class="v3"><asp:HyperLink runat="server" ID="lnkV3" 
                                            Text="3"
                                            NavigateUrl='<%# GetNavigateUrl((long)Eval("ID"), 3) %>' /></td>
                                        <td class="v4"><asp:HyperLink runat="server" ID="lnkV4"
                                            Text="4"
                                            NavigateUrl='<%# GetNavigateUrl((long)Eval("ID"), 4) %>' /></td>
                                        <td class="v5"><asp:HyperLink runat="server" ID="lnkV5"
                                            Text="5"
                                            NavigateUrl='<%# GetNavigateUrl((long)Eval("ID"), 5) %>' /></td></tr>
                                        <tr>
                                            <td colspan="2" class="small">Meh</td>
                                            <td colspan="3" class="small" align="right">Fundie!</td>
                                        </tr>
                                    </table>
                                </div>
                            
                                <%# DAL.YCodes.Format(Eval("FundieQuote") as string) %>
                            </p>
                            <p>
                                <%# Helpers.StringHelper.SafeFormat(Eval("Fundie")) %>,
                                <%# Helpers.StringHelper.SafeFormat("<a href=\"{0}\" target=\"_blank\">{1}</a>", Eval("URL"), Eval("Board")) %>
                                <%# Helpers.StringHelper.SafeFormat("[<a href=\"comments.aspx?q={0}\" target=\"_blank\">Comments ({1})</a>]", Eval("ID"), Eval("TotalComments")) %>
                                <%# Convert.ToDateTime(Eval("DatePosted")).ToString("[yyyy-MMM-dd]") %>
                                <asp:Panel runat="server" ID="pnlContributor" Width="100%"
                                    Visible='<%# Convert.ToBoolean(Eval("CreditContributor")) == true && !String.IsNullOrEmpty((Eval("Contributor") as string)) %>'>
                                        Submitted by <%# Helpers.StringHelper.SafeFormat(Eval("Contributor")) %>
                                </asp:Panel>
                                <asp:Panel runat="server" ID="pnlMod" Width="100%"
                                    Visible='<%# ShowModView() %>'>
                                        <asp:HyperLink runat="server" ID="lnkEditQuote"
                                            Text="Edit Quote"
                                            Target="_blank"
                                            NavigateUrl='<%# Helpers.StringHelper.SafeFormat("~/fundies/editquote.aspx?q={0}", Eval("ID")) %>' />
                                        |
                                        <asp:HyperLink runat="server" ID="HyperLink1"
                                            Text="Delete Quote"
                                            Target="_blank"
                                            NavigateUrl='<%# Helpers.StringHelper.SafeFormat("~/fundies/deletequote.aspx?q={0}", Eval("ID")) %>' />
                                </asp:Panel>
                            </p>
                        </td>
                    </tr>
                </table>
            </ItemTemplate>
            <SeparatorTemplate>
                <hr />
            </SeparatorTemplate>
        </asp:Repeater>
    </asp:View>
    <asp:View runat="server" ID="viewError">
        <i>Fundie quotes coming soon to a theatre near you!</i>
    </asp:View>
</asp:MultiView>